package AboutSort;

public class QuickSort2 {

    public int[] sort(int[] nums) {
        sortInner(0,nums.length-1,nums);
        return null;
    }

    private void sortInner(int l ,int r,int[] nums) {

        if(l > r) {
            return;
        }

        int base = nums[l];
        int i = l;
        int j = r;

        while( i < j ) {
            while(i < j && nums[j] >= base) {
                j--;
            }

            while(i < j && nums[i] <= base) {
                i++;
            }

            if(i < j) {
                int temp = nums[i];
                nums[i] = nums[j];
                nums[j] = temp;
            }
        }

        //交换基值
        nums[l] = nums[i];
        nums[i] = base;

        sortInner(l,i - 1,nums);
        sortInner(i+1,r,nums);
    }


}
